package com.bw.shopping.bind;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bw.mvvm_common.BaseApplication;
import com.bw.mvvm_common.field.UIField;
import com.bw.shopping.R;
import com.bw.shopping.mvvm.view.fragment.AddressActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.HashMap;

public
/**
 * @author Lishaohe
 * @description:
 * @date :2021/10/29 0029 下午 2:56
 *
 */
class OrderBind {
    @BindingAdapter(value = {"orderadapter","username","address"})
    public static void bindorder(
            RecyclerView recyclerView,
            BaseQuickAdapter adapter,
            String username,
            String address
    ){

        LinearLayoutManager manager = new LinearLayoutManager(recyclerView.getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        BaseQuickAdapter adapter1 = (BaseQuickAdapter) recyclerView.getAdapter();
        if (adapter1==null){
            View inflate = LayoutInflater.from(BaseApplication.getApplication()).inflate(R.layout.item_confirm_head, null);
            View inflate1 = LayoutInflater.from(BaseApplication.getApplication()).inflate(R.layout.view_confirm_foot, null);
            TextView TV = inflate.findViewById(R.id.mSelectShipTv);
            RelativeLayout RL = inflate.findViewById(R.id.mShipView);
            RL.setVisibility(View.GONE);
            TV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int i =1;
                    i++;
                    if (i%2==0){
                        RL.setVisibility(View.VISIBLE);
                    }else if (i%2!=0){
                        RL.setVisibility(View.GONE);
                    }
                }
            });
            TextView name = inflate.findViewById(R.id.mShipNameTv11);
            name.setText(username);
            TextView address111 = inflate.findViewById(R.id.mShipAddressTv11);
            address111.setText(address);
            ImageView go = inflate.findViewById(R.id.go);
            go.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    BaseApplication.getApplication().startActivity(new Intent(BaseApplication.getApplication(),AddressActivity.class));
                }
            });
            adapter.addHeaderView(inflate);
            adapter.addFooterView(inflate1);

        }else {
            LinearLayout headerLayout = adapter.getHeaderLayout();
            TextView TV = headerLayout.findViewById(R.id.mSelectShipTv);
            RelativeLayout RL = headerLayout.findViewById(R.id.mShipView);
            RL.setVisibility(View.GONE);
            TV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int i =1;
                    i++;
                    if (i%2==0){
                        RL.setVisibility(View.VISIBLE);
                    }else if (i%2!=0){
                        RL.setVisibility(View.GONE);
                    }
                }
            });
            TextView name = headerLayout.findViewById(R.id.mShipNameTv11);
            name.setText(username);
            TextView address111 = headerLayout.findViewById(R.id.mShipAddressTv11);
            address111.setText(address);
            ImageView go = headerLayout.findViewById(R.id.go);
            go.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    BaseApplication.getApplication().startActivity(new Intent(BaseApplication.getApplication(),AddressActivity.class));
                }
            });
        }

        recyclerView.setAdapter(adapter);


    }
}
